#!/bin/sh


PLATFORM=`uname -p`
if [ $PLATFORM = 'unknown' ]; then
   PLATFORM="i386"
fi

if [ -f /etc/redhat-release ]; then
   DISTRO=`rpm -q --queryformat='%{RELEASE}' redhat-release  | awk -F '.' '{print "rhel" $1}'`
elif   [ -f /etc/suse-release ]; then
   DISTRO=`rpm -q --queryformat='%{VERSION}' sles-release  | awk '{print "sles" $1}'`
fi


if [ `which scons 2> /dev/null` ]; then
  echo  "It seems you already have scons on this server.
  Assuming you already have SMX development dependencies installed."
  exit
fi


echo "--- Downloading req'ts for SMX provider development on the ($PLATFORM) platform --"
sleep 5

wget http://linux.fc.hp.com/~csmith/smx/smx-reqs.tar.gz
wget -r -l 1 -A "tog-pegasus*.$DISTRO.$PLATFORM.rpm" http://linux.fc.hp.com/manageability/downloads/smx/smxtp/last/
mv linux.fc.hp.com/manageability/downloads/smx/smxtp/last/*rpm .

wget http://linux.fc.hp.com/manageability/downloads/hpmgmtbase/beta/last/hpmgmtbase-devel.$DISTRO.$PLATFORM.rpm
wget http://linux.fc.hp.com/manageability/downloads/hpmgmtbase/beta/last/hpmgmtbase.$DISTRO.$PLATFORM.rpm
rm -rf linux.fc.hp.com

echo "--- Installing SMX req'ts  ---"
# untar bundle
tar zxvf smx-reqs.tar.gz 
cd smx-reqs

echo "     - Installing updated subversion for collabnet:"
if [ -d "svn1.5/$PLATFORM/$DISTRO" ]; then
  chmod 755  svn1.5/$PLATFORM/$DISTRO/svn
  echo "copying svn version 1.5 to /usr/local/bin"
  cp svn1.5/$PLATFORM/$DISTRO/svn /usr/local/bin
else
  echo "no updated subversion required."
fi

echo "     - Installing PyWBEM:"
sleep 1
# install pywbem
tar zxvf pywbem-*gz
cd pywbem-*
python ./setup.py build
python ./setup.py install
cd ..


# install scons and tog-pegasus
rpm -Uhv scons*rpm
cd ..
rpm -Uhv tog-pegasus-*rpm 
cimconfig -s forceProviderProcesses=true -p
/etc/init.d/tog-pegasus restart


echo "     - Installing Hpmgmtbase and hpmgmtbase-devel:"
sleep 1
# install hpmgmtbase and mgmtbase-devel for this platform
rpm -Uvh hpmgmtbase*rpm

# clean up
rm -rf pywbem-* tog-pegasus-*rpm scons*rpm hpmgmtbase*rpm 

echo -e "\n\n-------------------- DEVEL PREP COMPLETE ------------------\nIn order to begin building SMX providers, download oslo-smx using subversion with the commands: \nsvn co https://oslo-smx.csd200a.com/svn/oslo-smx/trunk oslo-smx\ncd oslo-smx; scons $PLATFORM-standalone\n\n If you wish to build an installable RPM, run this build command:\nscons RPM=pegasus $PLATFORM-standalone\n"
